#ifndef _PACKET_H
#define _PACKET_H
#include "logger.hpp"
#include <string>
#include <sstream>
using std::stringstream;
using std::string;

class Packet
{
public:
    Packet(const string & rec)
        :_type(-1)
         ,_length(0)
    {
        if(rec.size()<8){
            stringstream sstr;
            sstr.clear();
            sstr<<"the server receive msg size is "<<rec.size()<<" lesss 8."<<endl;
            LOG_ERROR(sstr.str().c_str());
            LOG_DEBUG(sstr.str().c_str());
        }else{
            _type= *reinterpret_cast<const int *>(rec.c_str());
            _length= *reinterpret_cast<const int *>(rec.c_str()+4);
            _msg = rec.c_str()+8;
        }
    }
    Packet(int type,int length,const char * msg):_type(type),_length(length),_msg(msg){}
    ~Packet() {}

public:
    int _type;
    int _length;
    string _msg;

};
#endif

